from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from django.views import View


 # 1.获取图片验证码 GET
class ImageCodeView(View):
    def get(self, request, uuid):
        # 1.校验 uuid , 正则 已经校验过了

        # 2.生成图片验证码
        from libs.captcha.captcha import captcha
        text, image_code = captcha.generate_captcha()

        # 3.想redis缓存 存 验证码text
        from django_redis import get_redis_connection
        image_redis_client = get_redis_connection('verify_image_code')
        image_redis_client.setex("img_%s" % uuid, 300, text)

        # 4.返回图片验证码 image_code
        return HttpResponse(image_code, content_type='image/jpeg')
